﻿

namespace ExtensionMethods.Test.Extensions
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Groundwork.Extensions;
    using FluentAssertions;

    [TestClass]
    public class SecurityTest
    {
        string testString;
        string antropy;

        

        [TestInitialize]
        public void Setup()
        {
            testString = "hello world";
            antropy = "testing123";
        }


        //[TestMethod]
        //public void RASEncryptTest()
        //{
        //    string value = "hello world";
        //    string encryptedValue = value.Encrypt();
        //    encryptedValue.Should().NotBe(value);
        //}


        //[TestMethod]
        //public void RASDecryptTest()
        //{
        //    string value = "hello world";
        //    string encryptedValue = value.Encrypt();
        //    string decrypted = encryptedValue.Decrypt();
        //    decrypted.Should().Be(value);
        //}
        [TestMethod]
        public void Sha1hashTest_CompareDifferentHashes()
        {
            string hash = "hello world".ToSha1();
            string checkString = "different string".ToSha1();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().NotBe(checkString);
        }

        [TestMethod]
        public void Sha1hashTest_CompareSameHashes()
        {
            string hash = "hello world".ToSha1();
            string checkString = "hello world".ToSha1();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().Be(checkString);
        }

        [TestMethod]
        public void Sha1hashTest_CompareEmptyStringHashes()
        {
            string hash = "".ToSha1();
            string checkString = "hello world".ToSha1();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().NotBe(checkString);
        }

        [TestMethod]
        public void Sha256hashTest_CompareDifferentHashes()
        {
            string hash = "hello world".ToSha256();
            string checkString = "different string".ToSha256();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().NotBe(checkString);
        }

        [TestMethod]
        public void Sha256hashTest_CompareSameHashes()
        {
            string hash = "hello world".ToSha256();
            string checkString = "hello world".ToSha256();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().Be(checkString);
        }

        [TestMethod]
        public void Sha256hashTest_CompareEmptyStringHashes()
        {
            string hash = "".ToSha256();
            string checkString = "hello world".ToSha256();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().NotBe(checkString);
        }

        [TestMethod]
        public void Md5hashTest_CompareDifferentHashes()
        {
            string hash = "hello world".ToMd5();
            string checkString = "different string".ToMd5();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().NotBe(checkString);
        }

        [TestMethod]
        public void Md5hashTest_CompareSameHashes()
        {
            string hash = "hello world".ToMd5();
            string checkString = "hello world".ToMd5();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().Be(checkString);
        }

        [TestMethod]
        public void Md5hashTest_CompareEmptyStringHashes()
        {
            string hash = "".ToMd5();
            string checkString = "hello world".ToMd5();
            hash.Should().NotBeNullOrEmpty();
            hash.Should().NotBe(checkString);
        }
        [TestMethod]
        public void ProtectStringTest()
        {

            byte[] protectedData = testString.Protect(antropy, System.Security.Cryptography.DataProtectionScope.CurrentUser);
            protectedData.Length.Should().BeGreaterThan(0);
        }

        [TestMethod]
        public void UnprotectedStringTest()
        {
            byte[] protectedData = testString.Protect(antropy, System.Security.Cryptography.DataProtectionScope.CurrentUser);
            string unprotectedData = protectedData.UnProtect(antropy, System.Security.Cryptography.DataProtectionScope.CurrentUser);
            unprotectedData.Should().Be(testString);
        }


    }
}
